<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>在线考试平台</title>
  <link rel="shortcut icon" href="images/1111.jpg" type="image/x-icon">
  <link href="css/bootstrap.min.css" rel="stylesheet">
</head>

<body>
  <div class="jumbotron jumbotron-fluid p-1">
    <div class="container">
      <h1 class="display-3">在线考试平台</h1>
      <p class="lead">选择题</p>
    </div>
  </div>

  <div id="app" class="container">
    <!-- 进度条 -->
    <div class="progress">
      <div class="progress-bar bg-info" role="progressbar"
      :style="{width: (progress*100/quiz.length)+'%'}"
      aria-valuemin="0" aria-valuemax="100" aria-valuenow="25"
      >完成进度</div>
    </div>
    <!-- 题目 单选 -->
    <div v-if="progress < size" class="jumbotron jumbotron-fluid mt-3">
      <div class="container">
        <h1 class="display-4">{{quiz[progress].subject}}</h1>
        <p>单选题</p>
        <hr class="my-2">
        <!-- 选项 -->
        <div v-for="(item, i) in quiz[progress].items" :key="i" class="form-check my-3">
          <label class="form-check-label">
            <input type="radio" class="form-check-input" name="i" v-model="answer" :value="itemsValue[i]">
            <span class="badge badge-pill badge-primary mx-3">{{itemsValue[i]}}</span>
            {{item}}
          </label>
        </div>
        <!-- 按钮 -->
        <div class="row">
          <div class="col-lg-6 col-xm-12">
            <button :disabled="progress===0" type="button" class="btn btn-danger btn-lg btn-block" @click="prev()">上一题</button>
          </div>
          <div class="col-lg-6 col-xm-12">
            <button :disabled="answer===''" type="button" class="btn btn-success btn-lg btn-block" @click="next()">下一题</button>
          </div>
        </div>
      </div>
    </div>
    <!-- 题目 多选 -->
    <div v-else-if='progress<quiz.length' class="jumbotron jumbotron-fluid mt-3">
      <div class="container">
        <h1 class="display-4">{{quiz[progress].subject}}</h1>
        <p>多选题</p>
        <hr class="my-2">
        <!-- 选项 -->
        <div v-for="(item, i) in quiz[progress].items" :key="i" class="form-check my-3">
          <label class="form-check-label">
            <input type="checkbox" class="form-check-input" name="i" v-model="multiAnswer" :value="itemsValue[i]">
            <span class="badge badge-pill badge-primary mx-3">{{itemsValue[i]}}</span>
            {{item}}
          </label>
        </div>
        <!-- 按钮 -->
        <div class="row">
          <div class="col-lg-6 col-xm-12">
            <button :disabled="progress===0" type="button" class="btn btn-danger btn-lg btn-block" @click="prev()">上一题</button>
          </div>
          <div class="col-lg-6 col-xm-12">
            <button :disabled="multiAnswer.length===0" type="button" class="btn btn-success btn-lg btn-block" @click="next()">下一题</button>
          </div>
        </div>
      </div>
    </div>
  </div>

  <script src="https://unpkg.com/vue/dist/vue.js"></script>
  <script>
    let app = new Vue({
      el: '#app',
      data() {
        return {
          quiz: [
            {
              subject: '最长的河？',
              items: ['尼罗河', '亚马逊', '恒河', '莱茵河'],
              ans: 'B'
            },
            {
              subject: '市值最高的公司？',
              items: ['移动', '阿里巴巴', '可口可乐', '苹果'],
              ans: 'D'
            },
            {
              subject: '最流行的设计语言？',
              items: ['PHP', 'Java', 'C', 'Python'],
              ans: 'D'
            },
            {
              subject: '最流行的数据库？',
              items: ['DB2', 'MySQL', 'Oracle', 'SQL Server'],
              ans: 'B'
            },
            {
              subject: '最流行的数据库2222？',
              items: ['DB2', 'MySQL', 'Oracle', 'SQL Server'],
              ans: 'B'
            },
            {
              subject: '水果？',
              items: ['苹果', '梨', '花生', '瓶酒'],
              ans: ['A', 'B']
            },
            {
              subject: '亚洲国家？',
              items: ['新加坡', '马来西亚', '澳大利亚', '美国'],
              ans: ['A', 'B']
            },
          ],
          progress: 0,
          itemsValue: ['A', 'B', 'C', 'D'],
          answer: '',
          answers: new Map(),
          submitted: false,
          score: 0,
          multiAnswer: [],
          size: 5,
        }
      },
      methods: {
        prev() {
          if(this.progress > 0 && this.progress < this.size) {
            this.progress--
            this.answer = this.answers.get(this.progress)
          }else{
            this.progress--
            this.multiAnswer = this.answers.get(this.progress)
          }
        },
        next() {
          if(this.progress < this.size) {
            this.answers.set(this.progress, this.answer)
            this.progress++
            console.log(this.answers);
            this.answer = ''
          }else if(this.progress < this.quiz.length) {
            this.answers.set(this.progress, this.multiAnswer)
            this.progress++
            console.log(this.answers);
            this.multiAnswer = []
          }
        },
        submit() {

        },
        back() {

        }
      }
    })
  </script>
</body>

</html>